package com.chen.blog.common.api;

import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @Description 通用返回对象
 * @Author zgyh2
 * @Date 2022/1/21 20:19
 * @Version 1.0
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class CommonResult {

    @ApiModelProperty(value = "响应码")
    private long code;

    @ApiModelProperty(value = "响应消息")
    private String message;

    @ApiModelProperty(value = "数据")
    private Object data;

    /**
     * 成功返回消息
     *
     * @param message
     * @return
     */
    public static CommonResult success(String message) {
        return new CommonResult(200, message, null);
    }

    /**
     * 成功返回结果
     *
     * @param message
     * @param data
     * @return
     */
    public static CommonResult success(String message, Object data) {
        return new CommonResult(200, message, data);
    }

    /**
     * 失败返回消息
     *
     * @param message
     * @return
     */
    public static CommonResult error(String message) {
        return new CommonResult(500, message, null);
    }
}
